package com.config;

import com.admin.entity.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * ClaseName：Swagger2
 * Description：
 * Author：JensenWei
 * QQ: 2188307188
 * Createtime：2018/2/27 20:55
 * Modified By：
 * Fixtime：2018/2/27 20:55
 * FixDescription：
 */

@Configuration
@EnableSwagger2
@ComponentScan(basePackages = {"com.admin.controller"})
public class Swagger2 {

    @Value("${swagger.enable}")
    private boolean enableSwagger;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("api")
                .apiInfo(apiInfo())
                .enable(enableSwagger)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.admin.controller"))//包名
                .paths(PathSelectors.any())
                .build()
                .ignoredParameterTypes(Address.class)
                .ignoredParameterTypes(Admin.class)
                .ignoredParameterTypes(AdminRole.class)
                .ignoredParameterTypes(Apk.class)
                .ignoredParameterTypes(City.class)
                .ignoredParameterTypes(Component.class)
                .ignoredParameterTypes(Content.class)
                .ignoredParameterTypes(DesktopConfig.class)
                .ignoredParameterTypes(Fileinfo.class)
                .ignoredParameterTypes(Group.class)
                .ignoredParameterTypes(Permission.class)
                .ignoredParameterTypes(Position.class)
                .ignoredParameterTypes(Province.class)
                .ignoredParameterTypes(Recharge.class)
                .ignoredParameterTypes(Region.class)
                .ignoredParameterTypes(Role.class)
                .ignoredParameterTypes(RolePermission.class)
                .ignoredParameterTypes(Screen.class)
                .ignoredParameterTypes(Station.class)
                .ignoredParameterTypes(StationKeyRecharge.class)
                .ignoredParameterTypes(StationRecharge.class)
                .ignoredParameterTypes(StationType.class)
                .ignoredParameterTypes(SystemApk.class)
                .ignoredParameterTypes(Terminal.class)
                .ignoredParameterTypes(TerminalKey.class)
                .ignoredParameterTypes(TGroup.class)
                .ignoredParameterTypes(UpAndDownLineRecord.class)
                .ignoredParameterTypes(WelcomePage.class)
                ;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("《英飞拓接口文档》")//大标题
                .description("description：项目摘要")//详细描述
                .termsOfServiceUrl("http://127.0.0.1:8080/")
                .contact("LiuQiYou")//作者
                .version("v1.0")//版本
                .build();
        }

}
